﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetBindDdl();
        }
    }

    private void GetBindDdl()
    {
        DropDownList1.Items.Clear();
        DropDownList1.Items.Add(new ListItem("--请选择--", "0"));
        string sql = "select * from Whir_CommonCategory where ParentId=1";
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        foreach (DataRow dr in dt.Rows)
        {
            DropDownList1.Items.Add(new ListItem(dr["CategoryName"].ToString(), dr["CategoryId"].ToString()));
        }

        DropDownList2.Items.Clear();
        DropDownList2.Items.Add(new ListItem("--请选择--", "0"));
        string sql2 = "select * from Whir_CommonCategory where ParentId=2";
        DataTable dt2 = Whir.SQLServerDAL.DbHelperSQL.Query(sql2).Tables[0];
        foreach (DataRow dr2 in dt2.Rows)
        {
            DropDownList2.Items.Add(new ListItem(dr2["CategoryName"].ToString(), dr2["CategoryId"].ToString()));
        }

    }


    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        if (txtPassWord.Value != txtPassWord2.Value)
        {
            Whir.Common.WebHelper.JsHelper.Alert(this.Page, "密码跟确认密码不一致，请重新输入！");
            return;
        }
        string sql1 = "select count(*) from Whir_U_Users where LoginName='" + txtUserName.Value + "'";
        int n = (int)Whir.SQLServerDAL.DbHelperSQL.GetSingle(sql1);
        if (n > 0)
        {
            Whir.Common.WebHelper.JsHelper.Alert(this.Page, "帐号已存在，请重新输入！");
            return;
        }


        //string sex = "女";
        //if (Sex1.Checked == true)
        //    sex = "男";
        //else
        //    sex = "女";


        string UserName = txtUserName.Value;
        string PassWord = txtPassWord.Value;


        string sql = "insert into Whir_U_Users (TypeID,CreateDate,LoginName,MemberPwd,TrueName,LinkTel,Address,CompanyName,WebSiteUrl,PostCode,Fax,industry,sex,CompanyTel,CompanyFax,QQ,IsCheck,Usergrade,Mobie,Email,NewH,NewI,characteristic,NewD,NLS,NewC,zscq,Products,frdb,YYZZ) values (@TypeID,@CreateDate,@LoginName,@MemberPwd,@TrueName,@LinkTel,@Address,@CompanyName,@WebSiteUrl,@PostCode,@Fax,@industry,@sex,@CompanyTel,@CompanyFax,@QQ,@IsCheck,@Usergrade,@Mobie,@Email,@NewH,@NewI,@characteristic,@NewD,@NLS,@NewC,@zscq,@Products,@frdb,@YYZZ)";

        SqlParameter[] pa =
        {
            new SqlParameter("@TypeID",85),
            new SqlParameter("@CreateDate",DateTime.Now),
            new SqlParameter("@LoginName",UserName),
            new SqlParameter("@MemberPwd",PassWord),
            new SqlParameter("@TrueName",txtName.Value),
            new SqlParameter("@LinkTel",txtTel.Value),
            new SqlParameter("@Address",txtCompanyAddress.Value),
            new SqlParameter("@CompanyName",txtCompanyName.Value),
            new SqlParameter("@WebSiteUrl",txtWebSiteUrl.Value),
            new SqlParameter("@PostCode",""),
            new SqlParameter("@Fax",txtFax.Value),
            new SqlParameter("@industry",""),
            new SqlParameter("@sex",""),
            new SqlParameter("@CompanyTel",txtCompanyTel.Value),
            new SqlParameter("@CompanyFax",txtCompanyFax.Value),
            new SqlParameter("@QQ",""),
            new SqlParameter("@IsCheck","否"),
            new SqlParameter("@Usergrade","1"),
            new SqlParameter("@Mobie",txtMobile.Value),
            new SqlParameter("@Email",txtEmail.Value),

            new SqlParameter("@NewH",txtCompanyName.Value),                                         //单位名称
            new SqlParameter("@NewI",DropDownList1.SelectedValue),                      //单位类型
            new SqlParameter("@characteristic",DropDownList2.SelectedValue),            //单位特性
            new SqlParameter("@NewD",txtNCZ.Value),                                     //年产值（万元）
            new SqlParameter("@NLS",txtNLS.Value),                                      //年利税
            new SqlParameter("@NewC",txtZCZZ.Value),                                    //注册资金（万元）
            new SqlParameter("@zscq",RadioButtonList1.SelectedValue),                   //是否拥有知识产权
            new SqlParameter("@Products",txtProducts.Value),                             //主营产品
            new SqlParameter("@frdb",txtFRDB.Value),                             //法人代表
            new SqlParameter("@YYZZ",txtYYZZ.Value)                             //营业执照

           
        };
        int count = Whir.SQLServerDAL.DbHelperSQL.ExecuteSql(sql, pa);
        if (count > 0)
        {
            // Session["UserName"] = UserName;
            Whir.Common.WebHelper.JsHelper.redirect(this.Page, "您已注册成功，我们将在2个工作日内完成审核请耐心等待，谢谢！", "Default.aspx");
            

        }
        else { Whir.Common.WebHelper.JsHelper.Alert(this.Page, "注册失败!"); }

    }
}
